<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改商户结算账户')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-accounts-updateSettle" th:object="${accounts}">
            <input name="id" th:value="${accounts.id}" type="hidden">
            <input name="merno" th:value="${accounts.seqId}" type="hidden"/>
            <input name="da_marker" th:value="${accounts.daMarker}" type="hidden"/>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">开户人名称：</label>
                <div class="col-sm-8">
                    <input name="screen_name" th:value="${accounts.screenName}" class="form-control" type="text" readonly>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">结算卡：</label>
                <div class="col-sm-8">
                    <input name="screen_num" th:value="${accounts.screenNum}" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">账户类型 ：</label>
                <div class="col-sm-8">
                    <span th:switch="${accounts.nature}">
                        <input type="hidden" name="nature" th:value="${accounts.nature}">
                        <input th:case="1" value="对公账户" class="form-control" type="text" readonly>
                        <input th:case="2" value="对私账户" class="form-control" type="text" readonly>
                    </span>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">预留手机号：</label>
                <div class="col-sm-8">
                    <input name="resphone" th:value="${accounts.resphone}" class="form-control" type="text" required>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label is-required">开户行名称：</label>
                <div class="col-sm-8">
                    <input name="bank_name" onclick="selectBranchBank()" readonly id="branchBank" th:value="${accounts.bankName}" type="text" placeholder="开户行名称" class="form-control" required>
                    <i class="fa fa-search" style="margin-top: -22px;margin-right:3px;float:right;"></i>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">总行名称：</label>
                <div class="col-sm-8">
                    <input name="bank_headname" readonly id="headBank" th:value="${accounts.bankHeadname}" type="text" placeholder="总行名称" class="form-control" required>
                </div>
            </div>
            <div class="form-group" th:if="*{nature+'' ne '2'}">
                <label class="col-sm-3 control-label is-required">支付系统行号：</label>
                <div class="col-sm-8">
                    <input type="text" name="bank_num" id="subbranchId" class="form-control" th:value="${accounts.bankNum}" readonly required/>
                </div>
            </div>
            <div class="form-group" th:if="*{nature+'' eq '2'}">
                <label class="col-sm-3 control-label is-required">结算人身份证号：</label>
                <div class="col-sm-8">
                    <input type="text" name="screen_idnum" class="form-control" th:value="${accounts.screenIdnum}" required/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">账户开户地：</label>
                <div class="col-sm-2" style="width: 120px;">
                    <select id="province" name="province"  onchange="javascript:window.province('p',this)" class="province form-control m-b" required>
                        <option value="">请选择</option>
                        <option th:each="p:${pList}" th:text="${p.areaName}" th:value="${p.areaCode}"  th:selected="${p.areaCode} eq ${province}"></option>
                    </select>
                </div>
                <div class="col-sm-2" style="width: 120px;">
                    <select id="city" name="city" onchange="javascript:window.province('c')" class="city form-control m-b" required>
                        <option value="">请选择</option>
                        <option th:each="c:${cList}" th:text="${c.areaName}" th:value="${c.areaCode}" th:selected="${c.areaCode} eq ${city}"></option>
                    </select>
                </div>
                <!--<div class="col-sm-2" style="width: 120px;">-->
                    <!--<select id="area" name="area" onchange="javascript:window.province('a')" class="area form-control m-b" required>-->
                        <!--<option value="">请选择</option>-->
                        <!--<option th:each="a:${aList}" th:text="${a.areaName}" th:value="${a.areaCode}" th:selected="${a.areaCode} eq ${area}"></option>-->
                    <!--</select>-->
                <!--</div>-->
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "accounts/accounts";
        $("#form-accounts-updateSettle").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/updateSettle", $('#form-accounts-updateSettle').serialize());
            }
        }

        function selectBranchBank() {
            var url = prefix + "/selectBranchBank";
            $.modal.open("选择支行" , url, '1000');
        }
        /**
         *
         * @param type 传入 省 p 市 c 区 a
         */
        function province(type,e) {
            var url = ctx + "area/area/list"; //获取地址信息
            if (type == 'p'){  //联动市
                if($("#province").find("option:selected").val() == ''){
                    defaultOption("city","请选择");
                    defaultOption("area","请选择");
                } else {
                    $.post(url,{'parentId':$("#province").val(),'areaType':'1'},function(result){
                        if (result.code == '0'){
                            initSelect("city",result);
                        }
                    });
                }
            } else if (type == 'c'){  //联动县
                $.post(url,{'parentId':$("#city").val(),'areaType':'2'},function(result){
                    if (result.code == '0',result){
                        initSelect("area",result);
                    }
                });
            }
            var name = $(e).attr("name");
            console.log(name);
            var text = $(e).find("option:selected").text()
            $("[name='"+name+"_name']").val(text);
        }
        //初始化 select选项
        function initSelect(selectId,data) {
            //清空旧的数据
            if (selectId == 'city'){
                $("#"+selectId).empty();
                $("#area").empty();
            }else{
                $("#"+selectId).empty();
            }
            var option = '<option value="">请选择</option>';
            data.rows.forEach(function(value){
                option += "<option value='"+value.areaCode+"'>"+value.areaName+"</option>";
            });
            $("#"+selectId).append(option);
        }
        //初始化 select选项
        function defaultOption(selectId,text) {
            $("#"+selectId).empty();
            $("#"+selectId).append("<option value=''>" + text +"</option>");
        }
    </script>
</body>
</html>